{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 基于ui.input的自动补全的代码自动补全单行器(未完善)\n",
    "> 2023/12/2 18:07\n",
    "\n",
    "\n",
    "options = ['print', 'if', 'True', 'False', 'else', 'import', 'def','input','from','in' ]\n",
    "text = ''''''\n",
    "inputs = \"\"\n",
    "\n",
    "def oninput(e):\n",
    "    global text\n",
    "    global inputs\n",
    "    print(e)\n",
    "    key = e.args['key']\n",
    "    if key=='Backspace':\n",
    "        if inputs == '':\n",
    "            lines = text.split(\"\\n\")  # 将文本块根据换行符进行分割\n",
    "            last_line = lines.pop()  # 弹出最后一行的值，赋值给last_line\n",
    "            inputs = last_line.strip()  # 去除前后空白字符，得到inputs的值\n",
    "            text = \"\\n\".join(lines)\n",
    "    if key=='Enter':\n",
    "        text +='\\n'+inputs\n",
    "        inputs=''\n",
    "    textlabel.set_value(text)\n",
    "\n",
    "def inputs_change(e):\n",
    "    global inputs\n",
    "    inputs = e.value\n",
    "    inputlabel.set_text(inputs)\n",
    "\n",
    "textlabel = ui.textarea('')\n",
    "inputs = ui.input(\"自动补全单行代码输入器\", autocomplete=options, on_change=lambda e: inputs_change(e)).on(\"keydown\",oninput)\n",
    "inputlabel = ui.label('')\n",
    "ui.button('打印text', on_click=lambda: ui.notify(text))"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "301f03982ff3d194"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "4b0ad44c2e74107f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
